package com.un.ebs.core.enums;

import com.un.ebs.core.metadata.EnumInfo;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description Description
 * @Author lcl
 * @Date Created in 2021/2/3
 */
@Getter
public enum DataTypeLengthEnum {

    NONE(DataTypeEnum.NONE.getCode(), "未知", "0"),
    OBJECT(DataTypeEnum.OBJECT.getCode(), "对象", "40"),
    STRING(DataTypeEnum.STRING.getCode(), "字符","20,40,50,100,255" ),
    NUMBER(DataTypeEnum.NUMBER.getCode(), "小数", "5,10,20"),
    INT(DataTypeEnum.INT.getCode(), "小数", "5,10,20"),
    DATE(DataTypeEnum.DATE.getCode(), "日期", "0"),
    DATETIME(DataTypeEnum.DATETIME.getCode(), "日期时间", "0"),
    MONEY(DataTypeEnum.MONEY.getCode(), "金额","5,10"),
    BOOLEAN(DataTypeEnum.BOOLEAN.getCode(), "逻辑", "0"),
    RESOURCE_DATA(DataTypeEnum.RESOURCE_DATA.getCode(), "字典", "40");

    private final int code;

    private final String value;


    private final String length;

    DataTypeLengthEnum(int code, String value, String length) {
        this.code = code;
        this.value = value;
        this.length = length;
    }


    public static DataTypeLengthEnum getEnumByCode(int code) {
        for (DataTypeLengthEnum dataTypeLengthEnum : DataTypeLengthEnum.values()) {
            if (code == dataTypeLengthEnum.getCode()) {
                return dataTypeLengthEnum;
            }
        }
        return null;
    }

    public static String[] getDataTypeLengthByCode(int dataTypeCode){
        for (DataTypeLengthEnum dataTypeLengthEnum : DataTypeLengthEnum.values()) {
            if (dataTypeCode == dataTypeLengthEnum.getCode()) {
                return dataTypeLengthEnum.getLength().split(",");
            }
        }
        return null;
    }

}
